package net.risesoft.risebi.collection.web;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.risesoft.risebi.commons.util.sqlfilter.JsonFilterResolver;
import net.risesoft.risebi.collection.model.Application;
import net.risesoft.risebi.collection.model.Catalog;
import net.risesoft.risebi.collection.model.EmployeeSoCollection;
import net.risesoft.risebi.collection.model.ReportInstance;
import net.risesoft.risebi.collection.model.ReportInstanceLevelStatus;
import net.risesoft.risebi.collection.model.ReportInstanceOperation;
import net.risesoft.risebi.collection.model.ReportPeriodType;
import net.risesoft.risebi.collection.model.ReportVerifyMessage;
import net.risesoft.risebi.collection.model.ReportWindowPeriod;
import net.risesoft.risebi.collection.model.Service;
import net.risesoft.risebi.collection.model.StatisticalObjectTree;
import net.risesoft.risebi.collection.model.StatisticalObjectTreeNode;
import net.risesoft.risebi.collection.model.Template;
import net.risesoft.risebi.collection.model.User;
import net.risesoft.risebi.collection.model.UserSO;
import net.risesoft.risebi.collection.service.ApplicationManager;
import net.risesoft.risebi.collection.service.CatalogManager;
import net.risesoft.risebi.collection.service.DataOperationManager;
import net.risesoft.risebi.collection.service.DbMetaDataManager;
import net.risesoft.risebi.collection.service.DynaBeanManager;
import net.risesoft.risebi.collection.service.EmployeeSoCollectionManager;
import net.risesoft.risebi.collection.service.PrivilegeManager;
import net.risesoft.risebi.collection.service.ReportInstanceLevelStatusManager;
import net.risesoft.risebi.collection.service.ReportInstanceManager;
import net.risesoft.risebi.collection.service.ReportInstanceOperationManager;
import net.risesoft.risebi.collection.service.ReportVerifyMessageManager;
import net.risesoft.risebi.collection.service.ReportWindowPeriodManager;
import net.risesoft.risebi.collection.service.ServiceManager;
import net.risesoft.risebi.collection.service.SoCollectionManager;
import net.risesoft.risebi.collection.service.StatisticalObjectTreeManager;
import net.risesoft.risebi.collection.service.TemplateManager;
import net.risesoft.risebi.collection.service.UserManager;
import net.risesoft.risebi.collection.service.UserSOManager;
import net.risesoft.risebi.commons.miscellaneouse.RiseBiConstants;
import net.risesoft.risebi.commons.util.GUID;
import net.risesoft.risebi.commons.util.JSONUtil;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.commons.beanutils.LazyDynaBean;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.web.util.HtmlUtils;
import org.springframework.web.util.JavaScriptUtils;

/**
 * 
 * @author <a href="mailto: baiyibing@gmail.com">王锤</a>
 * @version $Revision$
 * 
 */
public class BaseDataQueryAction extends BaseAction {
	private static final long serialVersionUID = 5211485835350544846L;
	private final Log log = LogFactory.getLog(BaseDataQueryAction.class);

	private ReportWindowPeriodManager reportWindowPeriodManager;
	private UserManager userManager;
	private UserSOManager userSOManager;
	private ReportInstanceManager reportInstanceManager;
	private ReportInstanceLevelStatusManager reportInstanceLevelStatusManager;
	private ReportInstanceOperationManager reportInstanceOperationManager;
	private TemplateManager templateManager;
	private EmployeeSoCollectionManager employeeSoCollectionManager;
	private SoCollectionManager soCollectionManager;
	private ApplicationManager applicationManager;
	private CatalogManager catalogManager;
	private StatisticalObjectTreeManager statisticalObjectTreeManager;
	private DbMetaDataManager dbMetaDataManager;
	private DynaBeanManager dynaBeanManager;
	private ReportVerifyMessageManager reportVerifyMessageManager;
	private ServiceManager serviceManager;
	private DataOperationManager dataOperationManager;
	private PrivilegeManager privilegeManager;
	
	private String jsonApp;
	private String jsonUgency;
	private String jsonNotice;
	private String jsonFilter;
	private String json1;
	private String json2;
	private String json3;
	private String json4;
	private String json5;
	
	private String soInstanceCode;
	private String soInstanceName;
	private String selectedAppGuid;
	private String selectedTemplateGuid;
	private String selectedPeriodTypeGuid;	
	private String selectedSoGuid;
	private String selectedSoTreeGuid;
	private String selectedStartSotNodeGuid;
	private String selectedStartSotNodeInstanceGuid;
	private String selectedEndSotNodeGuid;
	private String selectedSoCollectionGuid;
	private String selectedReportInstanceGuids;
	private boolean inWindow = true; //是否当前窗口期
	private Integer lockStatus;	
	private Integer reportStatus;	
	private Boolean isForced = false;	
	private String reportVerifyType;	
	private ReportVerifyMessage reportVerifyMessage;
	private User user;
	private String levelCode;
	private Integer levelCodeSubmitted;
	private Integer verifyStatus;
	
	public String buildQuery() throws Exception {
	    //user = (User)userManager.getObject(User.class, this.getSessionUser().getGuid());
	    user = this.getSessionUser();
	    String userGuid = user.getGuid();	    
	    
		String filter = null;
		if(this.jsonFilter!=null && this.jsonFilter.trim().length()>0){
			JsonFilterResolver filterResolver = new JsonFilterResolver();
			filter = filterResolver.getSql(JSONArray.fromObject(this.jsonFilter));
		}
		
		String baseSql = "";
		if(user.getUserType()==User.USERTYPE_SYSTEMMANAGER){
		    baseSql = reportInstanceManager.getNativeQurySql4SystemUser(
	                RiseBiConstants.DIALECTNAME,
	                this.getSessionUser(), 
	                inWindow, reportVerifyType, lockStatus, reportStatus, 
	                filter, this.getDefaultService().getGuid(), 
	                selectedAppGuid, selectedSoCollectionGuid,
	                selectedStartSotNodeGuid, selectedStartSotNodeInstanceGuid, selectedEndSotNodeGuid);
		}else{
		    baseSql = reportInstanceManager.getNativeQurySql4EnterpriseUser(
                    RiseBiConstants.DIALECTNAME,this.getSessionUser(), 
                    inWindow, reportVerifyType, lockStatus, reportStatus,filter);
		}
		
		String otherFilter = "";
		/*if(this.json1!=null && this.json1.trim().length()>0 && this.json2!=null && this.json2.trim().length()>0){
			otherFilter = " AND ri.So_Instance_Guid IN (select d1.Item_Guid from dyna_so_aqtb d1 where d1.xitongfenleiCode='" + this.json1 + "' AND d1.daquCode='" + this.json2 + "')";
		}else if(this.json1!=null && this.json1.trim().length()>0){
			otherFilter = " AND ri.So_Instance_Guid IN (select d1.Item_Guid from dyna_so_aqtb d1 where d1.xitongfenleiCode='" + this.json1 + "')";
		}else if(this.json2!=null && this.json2.trim().length()>0){
			otherFilter = " AND ri.So_Instance_Guid IN (select d1.Item_Guid from dyna_so_aqtb d1 where d1.daquCode='" + this.json2 + "')";
		}*/		
		
		if(this.levelCode!=null && this.levelCode.trim().length()>0){
			otherFilter += " AND ri.Level_Code like '" + this.levelCode + "%'";
			//otherFilter += " AND ri.Level_Code = '" + this.levelCode + "'";
		}else if(user.getUserType()==User.USERTYPE_SYSTEMMANAGER){			
			this.levelCode = user.getLevelCode();					
			if(this.levelCode!=null && this.levelCode.length()>0){
				otherFilter += " AND ri.Level_Code like '" + this.levelCode + "%'";
				//otherFilter += " AND ri.Level_Code = '" + this.levelCode + "'";
			}
		}
		
		if(this.levelCodeSubmitted != null){
		    switch(this.levelCodeSubmitted){
	        case 2:
	            otherFilter += " AND ri.LevelCode_Submitted is null";
	            break;
	        case 3:
	            otherFilter += " AND ri.LevelCode_Submitted is not null";
	            break;
	        case 4:                 
	            if(this.levelCode!=null && this.levelCode.length()>0){
	                otherFilter += " AND ri.LevelCode_Submitted='" + this.levelCode + "'";
	            }
	            break;
	        }
		}		
		
		if(this.verifyStatus != null && this.verifyStatus != -10000){
		    if(this.verifyStatus == 0){
		        otherFilter += " AND (ri.verifyStatus=0 OR ri.verifyStatus is null)";
		    }else{
		        otherFilter += " AND ri.verifyStatus=" + this.verifyStatus;
		    }
        }
		
		boolean isSuperAdmin = user.isSuperAdmin();
		if(user.getUserType() == User.USERTYPE_SYSTEMMANAGER && isSuperAdmin==false){
		    //找出用户分管的报表
		    //otherFilter += " AND ri.Template_guid in (select template_Guid from rpt_usertemplate ut where ut.user_Guid='" + userGuid + "' and ut.permission>1) ";
        }		
		
		if(otherFilter.length()>0){
			baseSql += otherFilter;
		}
		
		return baseSql;
	}
	
	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Action(value="refreshJson")
	public String refreshJson() throws Exception {	    
		try{
			List newList = new ArrayList();
			Map map = new HashMap();
			map.put("guid", "  ");
			map.put("name", "【全部】");
			newList.add(map);

			if("jsonApp".equalsIgnoreCase(this.whichJson)){
				List<Application> list = applicationManager.getAppsByServiceWithPermission(this.getDefaultService().getGuid(), this.getSessionUser());	
				for(Application t : list){
					map = new HashMap();
					map.put("guid", t.getGuid());
					map.put("name", t.getChineseName());
					newList.add(map);
				}
				this.json = JSONUtil.getJsonString("include","guid,name",newList);
			}else if("jsonPeriodTypeByApp".equalsIgnoreCase(this.whichJson)){
				//需要判断权限吗？
				//List<ReportPeriodType> list = reportPeriodTypeManager.getReportPeriodTypeByAppGuidWithPermission(this.selectedAppGuid, this.getSessionUser());
				Application app = (Application)applicationManager.getObject(Application.class, this.selectedAppGuid);
				List<Template> list = app.getTemplates();
				String reportPeriodTypes = "";
				for(Template t : list){
					ReportPeriodType rpt = t.getReportPeriodType();
					if(rpt!=null){
						String guid = t.getReportPeriodType().getGuid();
						String name = t.getReportPeriodType().getName();
						if(!reportPeriodTypes.contains(guid)){
							reportPeriodTypes += guid + ",";						
							map = new HashMap();
							map.put("guid", guid);
							map.put("name", name);
							newList.add(map);
						}
					}					
				}
				this.json = JSONUtil.getJsonString("include","guid,name",newList);				
			}else if("jsonTemplateByPeriodType".equalsIgnoreCase(this.whichJson)){
				//List<Template> list = applicationManager.getTemplatesWithPermission(this.selectedAppGuid, this.getSessionUser());
				List<Template> list = templateManager.getTemplatesByApplicationAndReportPeriodType(this.selectedAppGuid, this.selectedPeriodTypeGuid);
				for(Template t : list){
					map = new HashMap();
					map.put("guid", t.getGuid());
					map.put("name", t.getName());
					newList.add(map);
				}					
				this.json = JSONUtil.getJsonString("include","guid,name",newList);				
			}else if("jsonPeriodByTemplate".equalsIgnoreCase(this.whichJson)){
				List<ReportWindowPeriod> list = reportWindowPeriodManager.getWindowReportPeriodsByTid(this.selectedTemplateGuid);
				for(ReportWindowPeriod t : list){
					String guid = t.getReportPeriodGuid();
					String name = t.getReportPeriodName();
					map = new HashMap();
					map.put("guid", guid);
					map.put("name", name);
					newList.add(map);
				}					
				this.json = JSONUtil.getJsonString("include","guid,name",newList);				
			}else if("jsonSoCollectionByApp".equalsIgnoreCase(this.whichJson)){ 
				List<EmployeeSoCollection> list = employeeSoCollectionManager.getByUserAndType(this.selectedAppGuid, this.getSessionUser(), "1,2,3");				
				for(EmployeeSoCollection t : list){
					String guid = t.getSoCollection().getGuid();
					String name = t.getSoCollection().getName();
					map = new HashMap();
					map.put("guid", guid);
					map.put("name", name);
					newList.add(map);
				}					
				this.json = JSONUtil.getJsonString("include","guid,name",newList);			
			}else if("jsonSoByApp".equalsIgnoreCase(this.whichJson)){ 
				List<Catalog> list = catalogManager.getCatalogWithSoByApp(this.selectedAppGuid,false);	
				for(Catalog t : list){
					map = new HashMap();
					map.put("guid", t.getGuid());
					map.put("name", t.getName());
					newList.add(map);
				}
				this.json = JSONUtil.getJsonString("include","guid,name",newList);			
			}else if("jsonSoByAppExcludeVirtual".equalsIgnoreCase(this.whichJson)){ 
				List<Catalog> list = catalogManager.getCatalogWithSoByApp(this.selectedAppGuid,false);	
				for(Catalog t : list){
					map = new HashMap();
					map.put("guid", t.getGuid());
					map.put("name", t.getName());
					newList.add(map);
				}
				this.json = JSONUtil.getJsonString("include","guid,name",newList);			
			}else if("jsonSoTreeByApp".equalsIgnoreCase(this.whichJson)){ 
				List<StatisticalObjectTree> list = statisticalObjectTreeManager.getAllByApp(this.selectedAppGuid);	
				for(StatisticalObjectTree t : list){
					map = new HashMap();
					map.put("guid", t.getGuid());
					map.put("name", t.getName());
					newList.add(map);
				}
				this.json = JSONUtil.getJsonString("include","guid,name",newList);			
			}else if("jsonReportInstance4SystemUser".equalsIgnoreCase(this.whichJson)){ 
				String filter = null;
				if(this.jsonFilter!=null && this.jsonFilter.trim().length()>0){
					JsonFilterResolver filterResolver = new JsonFilterResolver();
					filter = filterResolver.getSql(JSONArray.fromObject(this.jsonFilter));
				}
				String baseSql = reportInstanceManager.getNativeQurySql4SystemUser(
						RiseBiConstants.DIALECTNAME,
						this.getSessionUser(), 
						inWindow, reportVerifyType, lockStatus, reportStatus, 
						filter, this.getDefaultService().getGuid(), 
						selectedAppGuid, selectedSoCollectionGuid, 
						selectedStartSotNodeGuid, selectedStartSotNodeInstanceGuid, selectedEndSotNodeGuid);
				String countSql = "SELECT COUNT(*) " + baseSql;
				String querySql = "SELECT ri.ReportInstance_Guid " + baseSql;
				
				BigInteger count = (BigInteger)reportInstanceManager.getUniqueObjectByNativeSql(countSql);
				List list = reportInstanceManager.find(querySql, this.start, this.limit, true);
				List newlist = new ArrayList();
				for(int i=0; i<list.size(); i++){
					String reportInstance_Guid = (String)list.get(i);
					ReportInstance ri = (ReportInstance)reportInstanceManager.getObject(ReportInstance.class, reportInstance_Guid);
					
					HashMap hm = new HashMap();
					hm.put("guid", reportInstance_Guid);
					hm.put("applicationName", ri.getApplication().getChineseName());
					hm.put("templateName", ri.getTemplate().getName());
					hm.put("periodTypeName", ri.getReportPeriodType().getName());
					hm.put("reportPeriodName", ri.getReportPeriod().getName());
					hm.put("soTypeName", ri.getSoType().getName());
					hm.put("soInstanceName", ri.getSoInstanceName());
					hm.put("soInstanceCode", ri.getSoInstanceCode());
					hm.put("lockStatus", ri.getLockStatus());
					hm.put("status", ri.getStatus());
					hm.put("levelCodeSubmitted", ri.getLevelCodeSubmitted());
					newlist.add(hm);
				}
				
				Map map2 = new HashMap();
				map2.put("count", count);
				map2.put("list", newlist);
				this.json = JSONUtil.getJsonString(null,null,map2);		
			}else if("jsonReportInstance4SystemUser4aqtb".equalsIgnoreCase(this.whichJson)){ 
				String baseSql = buildQuery();
				String countSql = "SELECT COUNT(*) " + baseSql;
				String querySql = "SELECT ri.ReportInstance_Guid, '1' " + baseSql;				
				BigInteger count = (BigInteger)reportInstanceManager.getUniqueObjectByNativeSql(countSql);
				List list = reportInstanceManager.find(querySql, this.start, this.limit, true);
				List newlist = new ArrayList();				
				for(int i=0; i<list.size(); i++){
					String reportInstance_Guid = "";
					if(list.get(i) instanceof Object[]){
						Object[] record = (Object[])list.get(i);
						reportInstance_Guid = (String)record[0];
					}else{
						reportInstance_Guid = (String)list.get(i);
					}
					
					ReportInstance ri = (ReportInstance)reportInstanceManager.getObject(ReportInstance.class, reportInstance_Guid);
					
					HashMap hm = new HashMap();
					hm.put("guid", reportInstance_Guid);
					hm.put("applicationName", ri.getApplication().getChineseName());
					hm.put("templateName", ri.getTemplate().getName());
					hm.put("periodTypeName", ri.getReportPeriodType().getName());
					hm.put("reportPeriodName", ri.getReportPeriod().getName());
					hm.put("soTypeName", ri.getSoType().getName());
					hm.put("soInstanceName", ri.getSoInstanceName());
					hm.put("soInstanceCode", ri.getSoInstanceCode());
					hm.put("verifyStatus", ri.getVerifyStatus()==null?0:ri.getVerifyStatus());
					hm.put("lockStatus", ri.getLockStatus());
					hm.put("status", ri.getStatus());
					hm.put("levelCodeSubmitted", ri.getLevelCodeSubmitted());

//					String s = ri.getLevelCodeSubmitted();
//					if(s==null || s.trim().length()==0){
//						hm.put("levelStatus", 2);
//					}else{
//						hm.put("levelStatus", 3);
//						if(this.levelCode!=null && this.levelCode.length()>0){
//							if(s.indexOf(this.levelCode)>-1){
//								hm.put("levelStatus", 4);
//							}
//						}
//					}						
					
					List listVerify = reportVerifyMessageManager.find("from ReportVerifyMessage u where u.reportInstanceGuid='" + reportInstance_Guid + "' and (u.type=2 or u.type=3) order by u.createTime desc");  
                    if(listVerify.size()>0){
                        reportVerifyMessage = (ReportVerifyMessage)listVerify.get(0);
                        //String s = JavaScriptUtils.javaScriptEscape(reportVerifyMessage.getContent());
                        String s = reportVerifyMessage.getOperatorName() + "," + reportVerifyMessage.getTitle() + "," + reportVerifyMessage.getCreateTime() + "<br />";
                        s += reportVerifyMessage.getContent();
                        hm.put("verifyMessage", s);
                    }else{
                        hm.put("verifyMessage", "无审核信息");
                    }
                    
					newlist.add(hm);
				}
				
				Map map2 = new HashMap();
				map2.put("count", count);
				map2.put("list", newlist);
				this.json = JSONUtil.getJsonString(null,null,map2);		
//			}else if("jsonReportInstance4AcceptanceApprove".equalsIgnoreCase(this.whichJson)){ 
//				user = (User)userManager.getObject(User.class, this.getSessionUser().getGuid());
//				this.levelCode = user.getLevelCode();
//				
//				List roleList = new ArrayList();
//				roleList.add("AAAAAAAAAAAAAAAAAAAAAAAAAAAA0004"); //数据审批员角色,负责数据验收、数据上报的审批
//				if(privilegeManager.checkUserInRoles(user.getGuid(), roleList)==false){
//					this.json = "";
//					return AJAX;
//				}
//				
//				List<ReportInstanceOperation> list;
//				if(this.inWindow == true){
//					list = reportInstanceOperationManager.find("from ReportInstanceOperation u where u.levelCode='" + this.levelCode + "' and u.status=2 and u.operateTime is null");
//				}else{
//					list = reportInstanceOperationManager.find("from ReportInstanceOperation u where u.levelCode='" + this.levelCode + "' and u.status=2 and u.operateTime is not null");
//				}
//				
//				int count = list.size();
//				if(count==0){
//					this.json = "";
//					return AJAX;
//				}
//				
//				if(start>count-1){
//					start = count;
//				}
//				
//				int endIndex = start + limit;
//				if(endIndex>count-1)
//					endIndex = count;
//				
//				List newlist = new ArrayList();
//				for(int i=start; i<endIndex; i++){
//					ReportInstanceOperation reportInstanceOperation = (ReportInstanceOperation)list.get(i);
//					ReportInstance ri = reportInstanceOperation.getReportInstance();
//					HashMap hm = new HashMap();
//					hm.put("guid", ri.getGuid());
//					hm.put("applicationName", ri.getApplication().getChineseName());
//					hm.put("templateName", ri.getTemplate().getName());
//					hm.put("periodTypeName", ri.getReportPeriodType().getName());
//					hm.put("reportPeriodName", ri.getReportPeriod().getName());
//					hm.put("soTypeName", ri.getSoType().getName());
//					hm.put("soInstanceName", ri.getSoInstanceName());
//					hm.put("soInstanceCode", ri.getSoInstanceCode());
//					hm.put("lockStatus", ri.getLockStatus());
//					hm.put("status", ri.getStatus());
//					
//					List<ReportInstanceLevelStatus> list1 = reportInstanceLevelStatusManager.find("from ReportInstanceLevelStatus t where t.levelCode='" + this.levelCode + "' and t.reportInstance.guid='" + ri.getGuid() + "'");
//					if(list1.size()==0){
//						hm.put("levelStatus", 0);
//					}else{
//						ReportInstanceLevelStatus reportInstanceLevelStatus = list1.get(0);
//						hm.put("levelStatus", reportInstanceLevelStatus.getStatus());
//					}
//					
//					newlist.add(hm);
//				}
//				
//				Map map2 = new HashMap();
//				map2.put("count", count);
//				map2.put("list", newlist);
//				this.json = JSONUtil.getJsonString(null,null,map2);
//			}else if("jsonReportInstance4SubmissionApprove".equalsIgnoreCase(this.whichJson)){ 
//				user = (User)userManager.getObject(User.class, this.getSessionUser().getGuid());
//				this.levelCode = user.getLevelCode();
//				
//				List roleList = new ArrayList();
//				roleList.add("AAAAAAAAAAAAAAAAAAAAAAAAAAAA0004"); //数据审批员角色,负责数据验收、数据上报的审批
//				if(privilegeManager.checkUserInRoles(user.getGuid(), roleList)==false){
//					this.json = "";
//					return AJAX;
//				}
//				
//				List<ReportInstanceOperation> list;
//				if(this.inWindow == true){
//					list = reportInstanceOperationManager.find("from ReportInstanceOperation u where u.levelCode='" + this.levelCode + "' and u.status=4 and u.operateTime is null");
//				}else{
//					list = reportInstanceOperationManager.find("from ReportInstanceOperation u where u.levelCode='" + this.levelCode + "' and u.status=4 and u.operateTime is not null");
//				}
//				
//				int count = list.size();
//				if(count==0){
//					this.json = "";
//					return AJAX;
//				}
//				
//				if(start>count-1){
//					start = count;
//				}
//				
//				int endIndex = start + limit;
//				if(endIndex>count-1)
//					endIndex = count;
//				
//				List newlist = new ArrayList();
//				for(int i=start; i<endIndex; i++){
//					ReportInstanceOperation reportInstanceOperation = (ReportInstanceOperation)list.get(i);
//					ReportInstance ri = reportInstanceOperation.getReportInstance();
//					HashMap hm = new HashMap();
//					hm.put("guid", ri.getGuid());
//					hm.put("applicationName", ri.getApplication().getChineseName());
//					hm.put("templateName", ri.getTemplate().getName());
//					hm.put("periodTypeName", ri.getReportPeriodType().getName());
//					hm.put("reportPeriodName", ri.getReportPeriod().getName());
//					hm.put("soTypeName", ri.getSoType().getName());
//					hm.put("soInstanceName", ri.getSoInstanceName());
//					hm.put("soInstanceCode", ri.getSoInstanceCode());
//					hm.put("lockStatus", ri.getLockStatus());
//					hm.put("status", ri.getStatus());
//
//					List<ReportInstanceLevelStatus> list1 = reportInstanceLevelStatusManager.find("from ReportInstanceLevelStatus t where t.levelCode='" + this.levelCode + "' and t.reportInstance.guid='" + ri.getGuid() + "'");
//					if(list1.size()==0){
//						hm.put("levelStatus", 0);
//					}else{
//						ReportInstanceLevelStatus reportInstanceLevelStatus = list1.get(0);
//						hm.put("levelStatus", reportInstanceLevelStatus.getStatus());
//					}
//					
//					newlist.add(hm);
//				}
//				
//				Map map2 = new HashMap();
//				map2.put("count", count);
//				map2.put("list", newlist);
//				this.json = JSONUtil.getJsonString(null,null,map2);
			}else if("jsonReportInstance4EnterpriseUser".equalsIgnoreCase(this.whichJson)){ 
			    String baseSql = buildQuery();
                String countSql = "SELECT COUNT(*) " + baseSql;
                String querySql = "SELECT ri.ReportInstance_Guid, '1' " + baseSql;
				BigInteger count = (BigInteger)reportInstanceManager.getUniqueObjectByNativeSql(countSql);
				List list = reportInstanceManager.find(querySql, this.start, this.limit, true);
				List newlist = new ArrayList();
				for(int i=0; i<list.size(); i++){
					String reportInstance_Guid = "";
                    if(list.get(i) instanceof Object[]){
                        Object[] record = (Object[])list.get(i);
                        reportInstance_Guid = (String)record[0];
                    }else{
                        reportInstance_Guid = (String)list.get(i);
                    }
                    
					ReportInstance ri = (ReportInstance)reportInstanceManager.getObject(ReportInstance.class, reportInstance_Guid);
					
					HashMap hm = new HashMap();
					hm.put("guid", reportInstance_Guid);
					hm.put("applicationName", ri.getApplication().getChineseName());
					hm.put("templateName", ri.getTemplate().getName());
					hm.put("periodTypeName", ri.getReportPeriodType().getName());
					hm.put("reportPeriodName", ri.getReportPeriod().getName());
					hm.put("soTypeName", ri.getSoType()==null?"NULL":ri.getSoType().getName());
					hm.put("soInstanceName", ri.getSoInstanceName());
					hm.put("soInstanceCode", ri.getSoInstanceCode());
					hm.put("verifyStatus", ri.getVerifyStatus());
					hm.put("lockStatus", ri.getLockStatus());
					hm.put("status", ri.getStatus());
					hm.put("levelCodeSubmitted", ri.getLevelCodeSubmitted());
					
					if(this.reportVerifyType!=null && this.reportVerifyType.trim().length()>0){
					    List listVerify = reportVerifyMessageManager.find("from ReportVerifyMessage u where u.reportInstanceGuid='" + reportInstance_Guid + "' and u.type=" + this.reportVerifyType);  
	                    if(listVerify.size()>0){
	                        reportVerifyMessage = (ReportVerifyMessage)listVerify.get(0);
	                        hm.put("verifyMessageReaded", reportVerifyMessage.getReaded());
	                        hm.put("verifyMessageGuid", reportVerifyMessage.getGuid());
	                    }else{
	                        hm.put("verifyMessageReaded", false);
	                        hm.put("verifyMessageGuid", "1111");
	                    }
					}					
					
					List listVerify2 = reportVerifyMessageManager.find("from ReportVerifyMessage u where u.reportInstanceGuid='" + reportInstance_Guid + "' and (u.type=2 or u.type=3) order by u.createTime desc");  
                    if(listVerify2.size()>0){
                        reportVerifyMessage = (ReportVerifyMessage)listVerify2.get(0);
                        //String s = JavaScriptUtils.javaScriptEscape(reportVerifyMessage.getContent());
                        String s = reportVerifyMessage.getOperatorName() + "," + reportVerifyMessage.getTitle() + "," + reportVerifyMessage.getCreateTime() + "<br />";
                        s += reportVerifyMessage.getContent();
                        hm.put("verifyMessage", s);
                    }else{
                        hm.put("verifyMessage", "无审核信息");
                    }
					
					newlist.add(hm);
				}
				
				Map map2 = new HashMap();
				map2.put("count", count);
				map2.put("list", newlist);
				this.json = JSONUtil.getJsonString(null,null,map2);		
			}else if("jsonListVerifyMessage".equalsIgnoreCase(this.whichJson)){
				User currentUser = this.getSessionUser();
				if(currentUser.getUserType()==User.USERTYPE_SYSTEMMANAGER){
					String filter = null;
					if(this.jsonFilter!=null && this.jsonFilter.trim().length()>0){
						JsonFilterResolver filterResolver = new JsonFilterResolver();
						filter = filterResolver.getSql(JSONArray.fromObject(this.jsonFilter));
					}
					
					String serviceGuids = "";
					List<Service> listServices = serviceManager.getServicesWithPermission(currentUser);
					for(Service s : listServices){
						if(serviceGuids.length()==0){
							serviceGuids = s.getGuid();
						}else{
							serviceGuids += "," + s.getGuid();
						}
					}
					
					String appGuids = "";
					List<Application> listApps = applicationManager.getAppsWithPermission(currentUser);
					for(Application app : listApps){
						if(appGuids.length()==0){
							appGuids = app.getGuid();
						}else{
							appGuids += "," + app.getGuid();
						}
					}
					
					String baseSql = reportInstanceManager.getNativeQurySql4SystemUser(
							RiseBiConstants.DIALECTNAME,currentUser, 
							inWindow, reportVerifyType, lockStatus, reportStatus, 
							filter, serviceGuids, appGuids, 
							selectedSoCollectionGuid,selectedStartSotNodeGuid, selectedStartSotNodeInstanceGuid, selectedEndSotNodeGuid);
					
					String countSql = "SELECT COUNT(*) FROM Rpt_ReportVerifyMessage rvm WHERE rvm.hidden=0 and rvm.type in (" + this.reportVerifyType + ") AND rvm.reportInstanceGuid IN (SELECT ri.ReportInstance_Guid " + baseSql + ")";
					String querySql = "SELECT verify_Guid FROM Rpt_ReportVerifyMessage rvm WHERE rvm.hidden=0 and rvm.type in (" + this.reportVerifyType + ") AND rvm.reportInstanceGuid IN (SELECT ri.ReportInstance_Guid " + baseSql + ")";
					
					BigInteger count = (BigInteger)reportVerifyMessageManager.getUniqueObjectByNativeSql(countSql);
					List list = reportVerifyMessageManager.find(querySql, this.start, this.limit, true);
					
					List newlist = new ArrayList();
					for(int i=0; i<list.size(); i++){
						String verify_Guid = (String)list.get(i);
						ReportVerifyMessage rvm = (ReportVerifyMessage)reportVerifyMessageManager.getObject(ReportVerifyMessage.class, verify_Guid);
						
						HashMap hm = new HashMap();
						hm.put("guid", rvm.getGuid());
						hm.put("title", rvm.getTitle());
						hm.put("type", rvm.getType());
						hm.put("createTime", rvm.getCreateTime()); //DateFormatUtils.format(n.getStartTime(),"yyyy-MM-dd")
						hm.put("readTime", rvm.getReadTime());
						hm.put("readed", rvm.getReaded());
						hm.put("hidden", rvm.getHidden());
						//hm.put("content", rvm.getContent());
						hm.put("operatorName", rvm.getOperatorName());
						hm.put("reportInstanceGuid", rvm.getReportInstanceGuid());
						ReportInstance ri = (ReportInstance)reportInstanceManager.getObject(ReportInstance.class, rvm.getReportInstanceGuid());
						hm.put("reportLockStatus", ri.getLockStatus());
						hm.put("reportStatus", ri.getStatus());
						
						newlist.add(hm);
					}
					
					Map map2 = new HashMap();
					map2.put("count", count);
					map2.put("list", newlist);
					this.json = JSONUtil.getJsonString(null,null,map2);	 					
				}else{
					String filter = null;
					if(this.jsonFilter!=null && this.jsonFilter.trim().length()>0){
						JsonFilterResolver filterResolver = new JsonFilterResolver();
						filter = filterResolver.getSql(JSONArray.fromObject(this.jsonFilter));
					}

					String baseSql = reportInstanceManager.getNativeQurySql4EnterpriseUser(
							RiseBiConstants.DIALECTNAME,this.getSessionUser(), 
							inWindow, reportVerifyType, lockStatus, reportStatus,filter);
	
					String countSql = "SELECT COUNT(*) FROM Rpt_ReportVerifyMessage rvm WHERE rvm.hidden=0 and rvm.type in (" + this.reportVerifyType + ") AND rvm.reportInstanceGuid IN (SELECT ri.ReportInstance_Guid " + baseSql + ")";
					String querySql = "SELECT verify_Guid FROM Rpt_ReportVerifyMessage rvm WHERE rvm.hidden=0 and rvm.type in (" + this.reportVerifyType + ") AND rvm.reportInstanceGuid IN (SELECT ri.ReportInstance_Guid " + baseSql + ")";
					
					BigInteger count = (BigInteger)reportVerifyMessageManager.getUniqueObjectByNativeSql(countSql);
					List list = reportVerifyMessageManager.find(querySql, this.start, this.limit, true);
					List newlist = new ArrayList();
					for(int i=0; i<list.size(); i++){
						String verify_Guid = (String)list.get(i);
						ReportVerifyMessage rvm = (ReportVerifyMessage)reportVerifyMessageManager.getObject(ReportVerifyMessage.class, verify_Guid);
						
						HashMap hm = new HashMap();
						hm.put("guid", rvm.getGuid());
						hm.put("title", rvm.getTitle());
						hm.put("type", rvm.getType());
						hm.put("createTime", rvm.getCreateTime());
						hm.put("readTime", rvm.getReadTime());
						hm.put("readed", rvm.getReaded());
						hm.put("hidden", rvm.getHidden());
						//hm.put("content", rvm.getContent());
						hm.put("operatorName", rvm.getOperatorName());
						hm.put("reportInstanceGuid", rvm.getReportInstanceGuid());
						ReportInstance ri = (ReportInstance)reportInstanceManager.getObject(ReportInstance.class, rvm.getReportInstanceGuid());
						hm.put("reportLockStatus", ri.getLockStatus());
						hm.put("reportStatus", ri.getStatus());
						
						newlist.add(hm);
					}
					
					Map map2 = new HashMap();
					map2.put("count", count);
					map2.put("list", newlist);
					this.json = JSONUtil.getJsonString(null,null,map2);
				}
			}else if("jsonSoInstance4EnterpriseUser".equalsIgnoreCase(this.whichJson)){
				ArrayList soInstancelist = new ArrayList();
				User user = this.getSessionUser();
				if(user.getUserType() == User.USERTYPE_ENTERPRISEUSER) { // 如果是企业填报用户
					if (user.getParentUser() == null) { 
						// 对于主账户来说,先查询RPT_USERSO表，再以查询出的soInstance作为起点，在对应的缺省管理树中查询出所有下级节点
						List<UserSO> lst = userSOManager.getUserSOByUid(user.getGuid());
						for(UserSO uso : lst){					
							StatisticalObjectTree tree = uso.getSo().getApplication().getDefaultSoTree();
							if(tree==null || tree.getGuid().trim().length()==0){
								addSoInstance(soInstancelist, uso.getSo(), uso.getSoInstanceGuid());
							}else{
								StatisticalObjectTreeNode startNode = tree.getNodeByCatalog(uso.getSo().getGuid());
								String nativeSQL = soCollectionManager.getSoTreeSQL(startNode.getGuid(), uso.getSoInstanceGuid(), null,true);
								List list = soCollectionManager.find(nativeSQL,true);
								for(int i=0; i<list.size(); i++){
									Object[] record = (Object[])list.get(i);
									Catalog so = (Catalog)catalogManager.getObject(Catalog.class, (String)record[0]);									
									addSoInstance(soInstancelist, so, (String)record[1]);									
								}
							}
						}
					} else {
						// 查询RPT_USERSO表，对于子账户来说，查询结果就是该子用户管理的所有调查对象。
						List<UserSO> lst = userSOManager.getUserSOByUid(user.getGuid());
						for(UserSO uso : lst){
							addSoInstance(soInstancelist, uso.getSo(), uso.getSoInstanceGuid());
						}
					}
				}
				this.json = JSONUtil.getJsonString(null,null,soInstancelist);		
			}else if("jsonSoInstance4SystemUser".equalsIgnoreCase(this.whichJson)){
				ArrayList soInstancelist = new ArrayList();
				String baseSql = "";
				String subQuery = "";
				String countSql = "";
				BigInteger count = new BigInteger("0");
				User user = this.getSessionUser();					
				
				Catalog so = (Catalog)catalogManager.getObject(Catalog.class, this.selectedSoGuid);
				String tableName = so.getTableName().trim().toLowerCase();			
				if (user.getUserType() == User.USERTYPE_SYSTEMMANAGER) { // 如果是管理用户
					baseSql = "SELECT catalog_guid,item_guid FROM " + tableName + " WHERE 1=1 \r\n";
					countSql = "SELECT count(*) FROM " + tableName + " WHERE 1=1 \r\n";
					if(this.soInstanceCode!=null && this.soInstanceCode.trim().length()>0){
						baseSql += "AND item_code LIKE '%" + this.soInstanceCode.trim() + "%' \r\n";
						countSql += "AND item_code LIKE '%" + this.soInstanceCode.trim() + "%' \r\n";
					}
					if(this.soInstanceName!=null && this.soInstanceName.trim().length()>0){
						baseSql += "AND item_name LIKE '%" + this.soInstanceName.trim() + "%' \r\n";
						countSql += "AND item_name LIKE '%" + this.soInstanceName.trim() + "%' \r\n";
					}
					
					// 调查对象集合范围条件
					if(this.selectedSoCollectionGuid != null && this.selectedSoCollectionGuid.trim().length()>0){
						subQuery = "(" + soCollectionManager.getSocMembersSQL(this.selectedSoCollectionGuid,false) + ")";
					}else if(user.isSuperAdmin()==false){ //不是超级用户，不能超越集合范围查询
						//取所有集合的调查对象实例的并集，这相当于该用户有权管理的实例集合。
						List<EmployeeSoCollection> lst = employeeSoCollectionManager.getByUserAndType(this.selectedAppGuid, this.getSessionUser(), "1,2,3");
						for(EmployeeSoCollection t : lst){
							if(subQuery.length()==0){
								subQuery = "(" + soCollectionManager.getSocMembersSQL(t.getSoCollection().getGuid(),false) + ")";
							}else{
								subQuery += "\r\n union \r\n" + "(" + soCollectionManager.getSocMembersSQL(t.getSoCollection().getGuid(),false) + ")";
							}						
						}
					}
					
					// 查询组织树条件
					if(this.selectedStartSotNodeGuid != null
						&& this.selectedStartSotNodeGuid.trim().length()>0
						&& this.selectedStartSotNodeInstanceGuid != null
						&& this.selectedStartSotNodeInstanceGuid.trim().length()>0)
					{
						if(subQuery.length()==0){
							subQuery = "(" + soCollectionManager.getSoTreeSQL(this.selectedStartSotNodeGuid, this.selectedStartSotNodeInstanceGuid, this.selectedEndSotNodeGuid,false) + ")";
						}else{
							//取SoCollection的实例集合与查询树的实例集合的交集。
							if("mssql".equals(RiseBiConstants.DIALECTNAME) || "oracle".equals(RiseBiConstants.DIALECTNAME)){
								subQuery += "\r\n INTERSECT \r\n" + "(" + soCollectionManager.getSoTreeSQL(this.selectedStartSotNodeGuid, this.selectedStartSotNodeInstanceGuid, this.selectedEndSotNodeGuid,false) + ")";
							}else{
								subQuery = "SELECT t.item_guid FROM (\r\n" +  
											subQuery + "\r\n" + 
											") AS t WHERE t.item_guid IN (\r\n" + 
											soCollectionManager.getSoTreeSQL(this.selectedStartSotNodeGuid, this.selectedStartSotNodeInstanceGuid, this.selectedEndSotNodeGuid,false) + 
											")";
							}
						}
					}
					
					if(subQuery.length()>0){
						baseSql += "AND item_guid IN ( \r\n" + 
									subQuery + "\r\n" + 
									") \r\n";
						countSql += "AND item_guid IN ( \r\n" + 
									subQuery + "\r\n" + 
									") \r\n";
					}
					
					count = (BigInteger)soCollectionManager.getUniqueObjectByNativeSql(countSql);
					List list = soCollectionManager.find(baseSql, this.start, this.limit, true);
					for(int i=0; i<list.size(); i++){
						Object[] record = (Object[])list.get(i);
						Catalog soTemp = (Catalog)catalogManager.getObject(Catalog.class, (String)record[0]);									
						addSoInstance(soInstancelist, soTemp, (String)record[1]);									
					}
				}
				
				Map map2 = new HashMap();
				map2.put("count", count);
				map2.put("list", soInstancelist);
				this.json = JSONUtil.getJsonString(null,null,map2);
			}
		}catch(Exception e){
			this.json = "[]";
			e.printStackTrace();
		} 

		return AJAX;
	}
	
	private void addSoInstance(ArrayList soInstancelist, Catalog so, String soInstanceGuid) throws Exception {
		boolean canAdd = true;
		HashMap<String,String> hm = new HashMap<String,String>();
		hm.put("applicationGuid", so.getAppGuid());
		hm.put("applicationName", so.getApplication().getChineseName());
		hm.put("soGuid", so.getGuid());
		hm.put("soTypeName", so.getSoType().getName());
		hm.put("soInstanceGuid", soInstanceGuid);
		
		String tableName = so.getTableName().toLowerCase();
		HashMap<String,Object> dynaBean = (HashMap<String,Object>)dynaBeanManager.getObject(tableName, soInstanceGuid);
		hm.put("soInstanceName", (String)dynaBean.get("item_name"));
		hm.put("soInstanceCode", (String)dynaBean.get("item_code"));
		
		if(this.selectedAppGuid!=null && this.selectedAppGuid.trim().length()>0){			
			if(hm.get("applicationGuid").equals(this.selectedAppGuid)){
				canAdd = canAdd && true;
			}else{
				canAdd = canAdd && false;
			}
		}
		
		if(this.selectedSoGuid!=null && this.selectedSoGuid.trim().length()>0){			
			if(hm.get("soGuid").equals(this.selectedSoGuid)){
				canAdd = canAdd && true;
			}else{
				canAdd = canAdd && false;
			}
		}
		
		if(this.soInstanceName!=null && this.soInstanceName.trim().length()>0){			
			if(hm.get("soInstanceName").contains(this.soInstanceName)){
				canAdd = canAdd && true;
			}else{
				canAdd = canAdd && false;
			}
		}
		
		if(this.soInstanceCode!=null && this.soInstanceCode.trim().length()>0){			
			if(hm.get("soInstanceCode").contains(this.soInstanceCode)){
				canAdd = canAdd && true;
			}else{
				canAdd = canAdd && false;
			}
		}
		
		if(canAdd){
			soInstancelist.add(hm);
		}
	}
	
	@Action(value="deleteReportDataBatch")
	public String deleteReportDataBatch() throws Exception {
		String[] guids = new String[0];
		LazyDynaBean ldb = new  LazyDynaBean();
		try{
			String baseSql = "";
			String updateSql = "";
			if("all".equals(this.selectedReportInstanceGuids)){
				String filter = null;
				if(this.jsonFilter!=null && this.jsonFilter.trim().length()>0){
					JsonFilterResolver filterResolver = new JsonFilterResolver();
					filter = filterResolver.getSql(JSONArray.fromObject(this.jsonFilter));
				}
				
				user = (User)userManager.getObject(User.class, this.getSessionUser().getGuid());
				this.levelCode = user.getLevelCode();
				if(this.levelCode==null || this.levelCode.length()==0){
					ldb.set("success", false);
					ldb.set("reason", "当前用户没有设置管理级别，不能进行本操作。");
					this.json = JSONObject.fromObject(ldb).toString();
					return AJAX;
				}
				
				baseSql = reportInstanceManager.getNativeQurySql4SystemUser(
						RiseBiConstants.DIALECTNAME,this.getSessionUser(), 
						inWindow, reportVerifyType, lockStatus, reportStatus, 
						filter, this.getDefaultService().getGuid(), 
						selectedAppGuid, selectedSoCollectionGuid, 
						selectedStartSotNodeGuid, selectedStartSotNodeInstanceGuid, selectedEndSotNodeGuid);
				//baseSql += " AND ri.Level_Code like '" + this.levelCode + "%'";
				baseSql += " AND ri.Level_Code = '" + this.levelCode + "'";
				
				List aList = reportInstanceManager.find("SELECT ri.ReportInstance_Guid " + baseSql, true);
				aList.toArray(guids);
			}else{
				guids = this.selectedReportInstanceGuids.split(",");
			}
			
			User user = this.getSessionUser();
			for(String guid : guids){
				dataOperationManager.removeData(guid, user);
			}
			
			ldb.set("success", true);
			ldb.set("reason", "删除成功!");
			this.json = JSONObject.fromObject(ldb).toString();
		}catch(Exception e){
			ldb.set("success", false);
			ldb.set("reason", e.getMessage());
			this.json = JSONObject.fromObject(ldb).toString();
			e.printStackTrace();
		}

		return AJAX;
	}

	@Action(value="lock")
	public String lock() throws Exception {
		LazyDynaBean ldb = new  LazyDynaBean();
		try{
			String baseSql = "";
			String updateSql = "";
			if("all".equals(this.selectedReportInstanceGuids)){
				user = this.getSessionUser();
				this.levelCode = user.getLevelCode();
				if(this.levelCode==null || this.levelCode.length()==0){
					ldb.set("success", false);
					ldb.set("reason", "当前用户没有设置管理级别，不能进行本操作。");
					this.json = JSONObject.fromObject(ldb).toString();
					return AJAX;
				}
				
				baseSql = buildQuery();
				updateSql = "UPDATE Rpt_ReportInstance t SET t.lockstatus=" + this.lockStatus + 
							" WHERE t.ReportInstance_Guid IN (SELECT ri.ReportInstance_Guid " + baseSql + ")";
			}else{
				String[] ss = this.selectedReportInstanceGuids.split(",");
				for(String s : ss){
					if(baseSql.length()==0){
						baseSql = "'" + s.trim() + "'";
					}else{
						baseSql += ",'" + s.trim() + "'";
					}
				}
				
				updateSql = "UPDATE Rpt_ReportInstance t SET t.lockstatus=" + this.lockStatus + 
							" WHERE t.ReportInstance_Guid IN (" + baseSql + ")";
			}
			
			reportInstanceManager.executeNativeSql(updateSql);
			
			ldb.set("success", true);
			ldb.set("reason", "更新成功!");
			this.json = JSONObject.fromObject(ldb).toString();
		}catch(Exception e){
			ldb.set("success", false);
			ldb.set("reason", e.getMessage());
			this.json = JSONObject.fromObject(ldb).toString();
			e.printStackTrace();
		}

		return AJAX;
	}
	
	@SuppressWarnings({ "rawtypes", "unchecked" })
	@Action(value="acceptanceStart") //启动验收流程
	public String acceptanceStart() throws Exception {
		LazyDynaBean ldb = new  LazyDynaBean();
		try{
			if(isForced==false){
				reportStatus = ReportInstance.STATUS_YES;
			}
			
			user = (User)userManager.getObject(User.class, this.getSessionUser().getGuid());
			this.levelCode = user.getLevelCode();
			if(this.levelCode==null || this.levelCode.length()==0){
				ldb.set("success", false);
				ldb.set("reason", "当前用户没有设置管理级别，不能进行本操作。");
				this.json = JSONObject.fromObject(ldb).toString();
				return AJAX;
			}
			
			String[] reportInstanceGuids = new String[]{};
			if("all".equals(this.selectedReportInstanceGuids)){
				String filter = null;
				if(this.jsonFilter!=null && this.jsonFilter.trim().length()>0){
					JsonFilterResolver filterResolver = new JsonFilterResolver();
					filter = filterResolver.getSql(JSONArray.fromObject(this.jsonFilter));
				}
				
				String baseSql = reportInstanceManager.getNativeQurySql4SystemUser(
						RiseBiConstants.DIALECTNAME,this.getSessionUser(), 
						inWindow, reportVerifyType, lockStatus, reportStatus, 
						filter, this.getDefaultService().getGuid(), 
						selectedAppGuid, selectedSoCollectionGuid, 
						selectedStartSotNodeGuid, selectedStartSotNodeInstanceGuid, selectedEndSotNodeGuid);
				//baseSql += " AND ri.Level_Code like '" + this.levelCode + "%'";
				baseSql += " AND ri.Level_Code = '" + this.levelCode + "'";
				String querySql = "SELECT ri.ReportInstance_Guid " + baseSql;
				List<String> list = reportInstanceManager.find(querySql, true);
				reportInstanceGuids = list.toArray(new String[]{});   
			}else{
				reportInstanceGuids = this.selectedReportInstanceGuids.split(",");
			}
			
			int allCount = reportInstanceGuids.length;
			int skipCount = 0;
			String message = "";
			for(String reportInstanceGuid : reportInstanceGuids){
				ReportInstance ri = (ReportInstance)reportInstanceManager.getObject(ReportInstance.class, reportInstanceGuid);
				if(ri.getStatus() != ReportInstance.STATUS_YES){
					if(isForced==false){
						skipCount++;
						message += ri.getSoInstanceName() + "\r\n";
						continue;
					}
				}
				
				ReportInstanceLevelStatus reportInstanceLevelStatus = new ReportInstanceLevelStatus();
				List list1 = reportInstanceLevelStatusManager.find("from ReportInstanceLevelStatus u where u.reportInstance.guid='" + reportInstanceGuid + "' and u.levelCode='" + this.levelCode + "'");	
				if(list1.size()>0){
					reportInstanceLevelStatus = (ReportInstanceLevelStatus)list1.get(0);
					//判断下级是否已经上报，如果status<1表示下级没有上报，则不能验收；status>1表示已经在验收审批阶段，则无需再次启动验收流程。
					if(reportInstanceLevelStatus.getStatus()!=1){
						skipCount++;
						message += ri.getSoInstanceName() + "\r\n";
						continue;
					}
					//设置正在验收标志
					reportInstanceLevelStatus.setStatus(ReportInstanceLevelStatus.STATUS_ACCEPTING);
					reportInstanceLevelStatusManager.saveObject(reportInstanceLevelStatus);
					
					//向ReportInstanceOperation拷贝数据，以便有审批权限的人员审批
					ReportInstanceOperation reportInstanceOperation = new ReportInstanceOperation();
					List list2 = reportInstanceOperationManager.find("from ReportInstanceOperation u where u.reportInstance.guid='" + reportInstanceGuid + "' and u.levelCode='" + this.levelCode + "' and u.status=2");	
					if(list2.size()>0){
						reportInstanceOperation = (ReportInstanceOperation)list2.get(0);
					}else{
						reportInstanceOperation.setGuid(new GUID().toString(32));
						reportInstanceOperation.setLevelCode(this.levelCode);
						reportInstanceOperation.setReportInstanceGuid(reportInstanceGuid);
						reportInstanceOperation.setStatus(2);
					}
					reportInstanceOperation.setSendTime(new Date());
					reportInstanceOperation.setSender(user);					
					reportInstanceOperationManager.saveObject(reportInstanceOperation);
				}else{		
					//在ReportInstanceLevelStatus中不存在，表示下级没有上报，则不能验收。
					reportInstanceLevelStatus = new ReportInstanceLevelStatus();
					reportInstanceLevelStatus.setGuid(new GUID().toString(32));
					reportInstanceLevelStatus.setLevelCode(this.levelCode);
					reportInstanceLevelStatus.setReportInstance(ri);
					reportInstanceLevelStatus.setStatus(0);
					reportInstanceLevelStatusManager.saveObject(reportInstanceLevelStatus);
					
					skipCount++;
					message += ri.getSoInstanceName() + "\r\n";
					continue;
				}
			}

			ldb.set("success", true);
			if(message.length()==0){
				ldb.set("reason", "提交验收审核，成功完成，总条数：" + allCount);
			}else{
				ldb.set("reason", "提交验收审核，完成，成功条数：" + (allCount-skipCount) + "\r\n下列报表由于还没有上报或者已经进入其他阶段，没有提交验收审核（个数：" + skipCount + "）:\r\n" + message);
			}
			
			this.json = JSONObject.fromObject(ldb).toString();
		}catch(Exception e){
			ldb.set("success", false);
			ldb.set("reason", e.getMessage());
			this.json = JSONObject.fromObject(ldb).toString();
			e.printStackTrace();
		}

		return AJAX;
	}
	
	@Action(value="prepareAcceptanceApprove",
			results={@Result(name="success", location="/client/datapage/listReportInstance4acceptance.jsp")}
	)
	public String prepareAcceptanceApprove() throws Exception {
		return SUCCESS;
	}
	
	@SuppressWarnings({ "rawtypes", "unchecked" })
	@Action(value="acceptanceApprove") //验收
	public String acceptanceApprove() throws Exception {
		LazyDynaBean ldb = new  LazyDynaBean();
		try{
			user = (User)userManager.getObject(User.class, this.getSessionUser().getGuid());
			this.levelCode = user.getLevelCode();
			if(this.levelCode==null || this.levelCode.length()==0){
				ldb.set("success", false);
				ldb.set("reason", "当前用户没有设置管理级别，不能进行本操作。");
				this.json = JSONObject.fromObject(ldb).toString();
				return AJAX;
			}
			
			String[] reportInstanceGuids = new String[]{};
			if("all".equals(this.selectedReportInstanceGuids)){
				List<ReportInstanceOperation> list1 = reportInstanceOperationManager.find("from ReportInstanceOperation u where u.levelCode='" + this.levelCode + "' and u.status=2");
				List<String> list2 = new ArrayList();
				for(ReportInstanceOperation a : list1){
					list2.add(a.getReportInstanceGuid());
				}
				reportInstanceGuids = list2.toArray(new String[]{});   
			}else{
				reportInstanceGuids = this.selectedReportInstanceGuids.split(",");
			}
			
			int allCount = reportInstanceGuids.length;
			int skipCount = 0;
			String message = "";
			for(String reportInstanceGuid : reportInstanceGuids){
				ReportInstance ri = (ReportInstance)reportInstanceManager.getObject(ReportInstance.class, reportInstanceGuid);
				List list1 = reportInstanceLevelStatusManager.find("from ReportInstanceLevelStatus u where u.reportInstance.guid='" + reportInstanceGuid + "' and u.levelCode='" + this.levelCode + "'");	
				if(list1.size()>0){
					ReportInstanceLevelStatus reportInstanceLevelStatus = (ReportInstanceLevelStatus)list1.get(0);
					//是否处于验收审批阶段，其他阶段都无需验收。
					if(reportInstanceLevelStatus.getStatus() != ReportInstanceLevelStatus.STATUS_ACCEPTING){
						skipCount++;
						message += ri.getSoInstanceName() + "\r\n";
						continue;
					}
					reportInstanceLevelStatus.setStatus(ReportInstanceLevelStatus.STATUS_ACCEPTED);
					reportInstanceLevelStatusManager.saveObject(reportInstanceLevelStatus);
					
					//在ReportInstanceOperation中设置验收时间
					List list2 = reportInstanceOperationManager.find("from ReportInstanceOperation u where u.reportInstance.guid='" + reportInstanceGuid + "' and u.levelCode='" + this.levelCode + "' and u.status=2");	
					ReportInstanceOperation reportInstanceOperation = (ReportInstanceOperation)list2.get(0);
					reportInstanceOperation.setOperateTime(new Date());//通过验收时间判断是否通过验收。
					reportInstanceOperation.setOperator(user);					
					reportInstanceOperationManager.saveObject(reportInstanceOperation);
				}else{
					skipCount++;
					message += ri.getSoInstanceName() + "\r\n";
					continue;
				}
			}

			ldb.set("success", true);
			if(message.length()==0){
				ldb.set("reason", "报表验收成功完成，总条数：" + allCount);
			}else{
				ldb.set("reason", "报表验收完成，成功条数：" + (allCount-skipCount) + "\r\n下列报表由于还没有上报或者已经验收，没有通过（个数：" + skipCount + "）:\r\n" + message);
			}
			
			this.json = JSONObject.fromObject(ldb).toString();
		}catch(Exception e){
			ldb.set("success", false);
			ldb.set("reason", e.getMessage());
			this.json = JSONObject.fromObject(ldb).toString();
			e.printStackTrace();
		}

		return AJAX;
	}
	
	@SuppressWarnings({"unchecked" })
	@Action(value="submission4SystemUser")
	public String submission4SystemUser() throws Exception {
		LazyDynaBean ldb = new  LazyDynaBean();
		try{
			user = (User)userManager.getObject(User.class, this.getSessionUser().getGuid());
			this.levelCode = user.getLevelCode();
			if(this.levelCode==null || this.levelCode.length()==0){
				ldb.set("success", false);
				ldb.set("reason", "当前用户没有设置管理级别，不能进行本操作。");
				this.json = JSONObject.fromObject(ldb).toString();
				return AJAX;
			}else if(this.levelCode.length() < 3){
				ldb.set("success", false);
				ldb.set("reason", "当前用户已经是最高管理级别，不能进行本操作。");
				this.json = JSONObject.fromObject(ldb).toString();
				return AJAX;
			}
			String parentlevelCode = getParentLevelCode(levelCode);
			
			String[] reportInstanceGuids = new String[]{};
			if("all".equals(this.selectedReportInstanceGuids)){
				String baseSql = buildQuery();
				String querySql = "SELECT ri.ReportInstance_Guid " + baseSql;
				List<String> list = reportInstanceManager.find(querySql, true);
				reportInstanceGuids = list.toArray(new String[]{});   //注意内存问题
			}else{
				reportInstanceGuids = this.selectedReportInstanceGuids.split(",");
			}
			
			int allCount = reportInstanceGuids.length;
			int successCount = 0;
			//String message = "";
			for(String reportInstanceGuid : reportInstanceGuids){
				ReportInstance ri = (ReportInstance)reportInstanceManager.getObject(ReportInstance.class, reportInstanceGuid);
				if(ri.getStatus() != ReportInstance.STATUS_YES){
					if(this.isForced==false){
						continue;
					}
				}
				
				String s = ri.getLevelCodeSubmitted();
				if(s!=null && s.trim().length()>0){
					int len1 = s.length();
					int len2 = parentlevelCode.length();
					int i = s.indexOf(parentlevelCode);
					if(i>-1 && (len1-len2)==3){
						//直接下级已报，才能继续上报
						ri.setLevelCodeSubmitted(parentlevelCode);
						reportInstanceManager.saveObject(ri);
						successCount++;
					}
				}
			}

			ldb.set("success", true);
			if(successCount==allCount){
				ldb.set("reason", "上报全部完成，总条数：" + allCount);	
			}else{
				ldb.set("reason", "上报部分完成，总条数：" + allCount + ", \r\n没有上报个数：" + (allCount-successCount));
			}
			
			this.json = JSONObject.fromObject(ldb).toString();
		}catch(Exception e){
			ldb.set("success", false);
			ldb.set("reason", e.getMessage());
			this.json = JSONObject.fromObject(ldb).toString();
			e.printStackTrace();
		}

		return AJAX;
	}
	
	@SuppressWarnings({"unchecked" })
	@Action(value="submission4EnterpriseUser")
	public String submission4EnterpriseUser() throws Exception {
		LazyDynaBean ldb = new  LazyDynaBean();
		try{			
			user = (User)userManager.getObject(User.class, this.getSessionUser().getGuid());
			this.levelCode = user.getLevelCode();
			if(this.levelCode==null || this.levelCode.length()==0){
				ldb.set("success", false);
				ldb.set("reason", "当前用户没有设置管理级别，不能进行本操作。");
				this.json = JSONObject.fromObject(ldb).toString();
				return AJAX;
			}
			
			ReportInstance ri = (ReportInstance)reportInstanceManager.getObject(ReportInstance.class, node);
			Integer lockStatus = ri.getLockStatus();
			if(lockStatus!=null && lockStatus==1){
				ldb.set("success", false);
				ldb.set("reason", "本条记录已经锁定，不能进行本操作。");
				this.json = JSONObject.fromObject(ldb).toString();
				return AJAX;
			}
			
			Integer status = ri.getStatus();
			if(status==null || status!=ReportInstance.STATUS_YES){
				if(this.isForced==false){
					ldb.set("success", false);
					ldb.set("reason", "本条数据有错误，不能进行本操作。");
					this.json = JSONObject.fromObject(ldb).toString();
					return AJAX;
				}
			}
			
			ri.setLevelCodeSubmitted(this.levelCode);
			reportInstanceManager.saveObject(ri);
			
			ldb.set("success", true);
			ldb.set("reason", "上报成功完成。");			
			this.json = JSONObject.fromObject(ldb).toString();
		}catch(Exception e){
			ldb.set("success", false);
			ldb.set("reason", e.getMessage());
			this.json = JSONObject.fromObject(ldb).toString();
			//e.printStackTrace();
		}

		return AJAX;
	}
	
	@Action(value="prepareSubmissionApprove",
			results={@Result(name="success", location="/client/datapage/listReportInstance4submission.jsp")}
	)
	public String prepareSubmissionApprove() throws Exception {
		return SUCCESS;
	}
	
	private String getParentLevelCode(String levelCode){
		String parentLevelCode = "";
		
		if(levelCode.trim().length()>=3){
			parentLevelCode = levelCode.substring(0, levelCode.length()-3);
		}
		
		return parentLevelCode;
	}
	
	@SuppressWarnings({ "rawtypes", "unchecked" })
	@Action(value="submissionApprove")
	public String submissionApprove() throws Exception {
		LazyDynaBean ldb = new  LazyDynaBean();
		try{
			user = (User)userManager.getObject(User.class, this.getSessionUser().getGuid());
			this.levelCode = user.getLevelCode();
			if(this.levelCode==null || this.levelCode.length()==0){
				ldb.set("success", false);
				ldb.set("reason", "当前用户没有设置管理级别，不能进行本操作。");
				this.json = JSONObject.fromObject(ldb).toString();
				return AJAX;
			}else if(this.levelCode.length() < 8){
				ldb.set("success", false);
				ldb.set("reason", "当前用户已经是最高管理级别，不能进行本操作。");
				this.json = JSONObject.fromObject(ldb).toString();
				return AJAX;
			}
			String parentlevelCode = getParentLevelCode(levelCode);
			
			String[] reportInstanceGuids = new String[]{};
			if("all".equals(this.selectedReportInstanceGuids)){
				List<ReportInstanceOperation> list1 = reportInstanceOperationManager.find("from ReportInstanceOperation u where u.levelCode='" + this.levelCode + "' and u.status=4");
				List<String> list2 = new ArrayList();
				for(ReportInstanceOperation a : list1){
					list2.add(a.getReportInstanceGuid());
				}
				reportInstanceGuids = list2.toArray(new String[]{});   
			}else{
				reportInstanceGuids = this.selectedReportInstanceGuids.split(",");
			}
			
			int allCount = reportInstanceGuids.length;
			int skipCount = 0;
			String message = "";
			for(String reportInstanceGuid : reportInstanceGuids){
				ReportInstance ri = (ReportInstance)reportInstanceManager.getObject(ReportInstance.class, reportInstanceGuid);
				if(ri.getStatus() != ReportInstance.STATUS_YES){
					if(isForced==false){
						skipCount++;
						message += ri.getSoInstanceName() + "\r\n";
						continue;
					}
				}
				
				List list1 = reportInstanceLevelStatusManager.find("from ReportInstanceLevelStatus u where u.reportInstance.guid='" + reportInstanceGuid + "' and u.levelCode='" + this.levelCode + "'");	
				if(list1.size()>0){					
					//是否处于上报审批阶段，其他阶段都无需上报。
					ReportInstanceLevelStatus reportInstanceLevelStatus = (ReportInstanceLevelStatus)list1.get(0);
					if(reportInstanceLevelStatus.getStatus() != ReportInstanceLevelStatus.STATUS_SUBMITTING){
						skipCount++;
						message += ri.getSoInstanceName() + "\r\n";
						continue;
					}
					
					//更新本级的ReportInstanceLevelStatus的status标记
					reportInstanceLevelStatus.setStatus(ReportInstanceLevelStatus.STATUS_SUBMITTED);
					reportInstanceLevelStatusManager.saveObject(reportInstanceLevelStatus);
					
					//在ReportInstanceOperation中设置验收时间
					List list2 = reportInstanceOperationManager.find("from ReportInstanceOperation u where u.reportInstance.guid='" + reportInstanceGuid + "' and u.levelCode='" + this.levelCode + "' and u.status=4");	
					ReportInstanceOperation reportInstanceOperation = (ReportInstanceOperation)list2.get(0);
					reportInstanceOperation.setOperateTime(new Date());
					reportInstanceOperation.setOperator(user);
					reportInstanceOperationManager.saveObject(reportInstanceOperation);
					
					//更新上级的ReportInstanceLevelStatus
					List list3 = reportInstanceLevelStatusManager.find("from ReportInstanceLevelStatus u where u.reportInstance.guid='" + reportInstanceGuid + "' and u.levelCode='" + parentlevelCode + "'");
					ReportInstanceLevelStatus reportInstanceLevelStatusParent;
					if(list3.size()>0){
						reportInstanceLevelStatusParent = (ReportInstanceLevelStatus)list3.get(0);
						if(reportInstanceLevelStatusParent.getStatus()==0){
							reportInstanceLevelStatusParent.setStatus(ReportInstanceLevelStatus.STATUS_REPORTED);
							reportInstanceLevelStatusManager.saveObject(reportInstanceLevelStatusParent);
						}
					}else{
						reportInstanceLevelStatusParent = new ReportInstanceLevelStatus();
						reportInstanceLevelStatusParent.setGuid(new GUID().toString(32));
						reportInstanceLevelStatusParent.setLevelCode(parentlevelCode);
						reportInstanceLevelStatusParent.setReportInstance(ri);
						reportInstanceLevelStatusParent.setStatus(ReportInstanceLevelStatus.STATUS_REPORTED);
						reportInstanceLevelStatusManager.saveObject(reportInstanceLevelStatusParent);
					}					
				}else{
					skipCount++;
					message += ri.getSoInstanceName() + "\r\n";
					continue;
				}
			}

			ldb.set("success", true);
			if(message.length()==0){
				ldb.set("reason", "报表上报成功完成，总条数：" + allCount);
			}else{
				ldb.set("reason", "报表上报完成，成功条数：" + (allCount-skipCount) + "\r\n下列报表由于还没有验收，没有上报（个数：" + skipCount + "）:\r\n" + message);
			}
			
			this.json = JSONObject.fromObject(ldb).toString();
		}catch(Exception e){
			ldb.set("success", false);
			ldb.set("reason", e.getMessage());
			this.json = JSONObject.fromObject(ldb).toString();
			e.printStackTrace();
		}

		return AJAX;
	}
	
	@SuppressWarnings("unchecked")
    @Action(value="verifyData")
    public String verifyData() throws Exception {
	    LazyDynaBean ldb = new  LazyDynaBean();
        try{
            user = this.getSessionUser();
            String userName = user.getName().trim().toLowerCase();
            this.levelCode = user.getLevelCode();
            if(this.levelCode==null || this.levelCode.length()==0){
                ldb.set("success", false);
                ldb.set("reason", "当前用户没有设置管理级别，不能进行本操作。");
                this.json = JSONObject.fromObject(ldb).toString();
                return AJAX;
            }
            
            int levels = this.levelCode.split("-").length - 1;
            int vStatus = 0;
            switch(levels){
            case 0: //国家级
                vStatus = 500;
                break;
            case 1: //省级
                vStatus = 400;
                break;
            case 2: //地市级
                vStatus = 300;
                break;
            case 3: //区县级
                vStatus = 200;
                break;
            case 4: //街道级
                vStatus = 100;
                break;
            }
            
            ReportInstance ri = (ReportInstance)reportInstanceManager.getObject(ReportInstance.class, this.node);  
            //String levelCodeSubmitted = ri.getLevelCodeSubmitted();
            //int levelsSubmitted = levelCodeSubmitted.split("-").length - 1; 

            if("1".equals(this.json1)){   //审核通过
                ri.setVerifyStatus(vStatus);
                ri.setLockStatus(1);
            }else{ //审核未通过
                ri.setVerifyStatus(-vStatus);
                ri.setLockStatus(0);
            }
            reportInstanceManager.saveObject(ri);
            
            ReportVerifyMessage verifyMessage = new ReportVerifyMessage();
            verifyMessage.setGuid(new GUID().toString(32));
            verifyMessage.setCreateTime(new Date());
            verifyMessage.setReadTime(new Date());
            verifyMessage.setHidden(false);
            verifyMessage.setReaded(false);
            verifyMessage.setOperatorName(this.getSessionUser().getRealName());
            verifyMessage.setReportInstanceGuid(this.node);
            if("1".equals(this.json1)){
                verifyMessage.setContent(ri.getTemplate().getName() + "\n\r" + this.json2);
                verifyMessage.setTitle("报表审核通过。");
                verifyMessage.setType(3);
            }else{
                verifyMessage.setContent(ri.getTemplate().getName() + "\n\r" + this.json2);
                verifyMessage.setTitle("报表审核没有通过。");
                verifyMessage.setType(2);
            }            
            reportVerifyMessageManager.saveObject(verifyMessage);
            
            ldb.set("success", true);
            ldb.set("reason", "报表审核任务成功完成!");
            this.json = JSONObject.fromObject(ldb).toString();
        }catch(Exception e){
            ldb.set("success", false);
            ldb.set("reason", e.getMessage());
            this.json = JSONObject.fromObject(ldb).toString();
            e.printStackTrace();
        }

        return AJAX;
	}
	
	@Action(value="verify")
	public String verify() throws Exception {
		LazyDynaBean ldb = new  LazyDynaBean();
		try{
			if("all".equals(this.selectedReportInstanceGuids)){
				String filter = null;
				if(this.jsonFilter!=null && this.jsonFilter.trim().length()>0){
					JsonFilterResolver filterResolver = new JsonFilterResolver();
					filter = filterResolver.getSql(JSONArray.fromObject(this.jsonFilter));
				}
				
				if(reportVerifyType!=null && reportVerifyType.contains("1")){
					lockStatus = 0;  //只能催报未锁定、未填报的表报。
					reportStatus = 0;
				}
				
				user = (User)userManager.getObject(User.class, this.getSessionUser().getGuid());
				this.levelCode = user.getLevelCode();
				if(this.levelCode==null || this.levelCode.length()==0){
					ldb.set("success", false);
					ldb.set("reason", "当前用户没有设置管理级别，不能进行本操作。");
					this.json = JSONObject.fromObject(ldb).toString();
					return AJAX;
				}
				
				String baseSql = reportInstanceManager.getNativeQurySql4SystemUser(
						RiseBiConstants.DIALECTNAME,this.getSessionUser(), 
						inWindow, reportVerifyType, lockStatus, reportStatus, 
						filter, this.getDefaultService().getGuid(), 
						selectedAppGuid, selectedSoCollectionGuid, 
						selectedStartSotNodeGuid, selectedStartSotNodeInstanceGuid, selectedEndSotNodeGuid);
				//baseSql += " AND ri.Level_Code like '" + this.levelCode + "%'";
				baseSql += " AND ri.Level_Code = '" + this.levelCode + "'";
				String querySql = "SELECT ri.ReportInstance_Guid " + baseSql;
				List list = reportInstanceManager.find(querySql, true);
				for(int i=0; i<list.size(); i++){
					ReportVerifyMessage verifyMessage = new ReportVerifyMessage();
					String reportInstance_Guid = (String)list.get(i);
					List listVerify = reportVerifyMessageManager.find("from ReportVerifyMessage u where u.reportInstanceGuid='" + reportInstance_Guid + "' and u.type=" + this.reportVerifyType);	
					if(listVerify.size()>0){
						verifyMessage = (ReportVerifyMessage)listVerify.get(0);
					}else{
						verifyMessage.setGuid(new GUID().toString(32));
					}					
					
					verifyMessage.setCreateTime(new Date());
					verifyMessage.setReadTime(new Date());
					verifyMessage.setHidden(false);					
					verifyMessage.setReaded(false);
					//User user = (User)userManager.getObject(User.class, this.getSessionUser().getGuid());
					verifyMessage.setOperatorName(this.getSessionUser().getRealName());//后台任务应设置为：systemTask					
					verifyMessage.setReportInstanceGuid(reportInstance_Guid);
					verifyMessage.setType(Integer.valueOf(reportVerifyType));
					
					ReportInstance ri = (ReportInstance)reportInstanceManager.getObject(ReportInstance.class, reportInstance_Guid);
					verifyMessage.setTitle(ri.getReportPeriod().getName()+"-"+ri.getTemplate().getName()+"-"+ri.getApplication().getChineseName()+"-"+ri.getSoInstanceName());
					verifyMessage.setContent("请尽快填写报表.");
					reportVerifyMessageManager.saveObject(verifyMessage);
				}
			}else{
				String[] reportInstanceGuids = this.selectedReportInstanceGuids.split(",");
				for(String reportInstanceGuid : reportInstanceGuids){
					ReportVerifyMessage verifyMessage = new ReportVerifyMessage();
					List listVerify = reportVerifyMessageManager.find("from ReportVerifyMessage u where u.reportInstanceGuid='" + reportInstanceGuid + "' and u.type=" + this.reportVerifyType);
					if(listVerify.size()>0){
						verifyMessage = (ReportVerifyMessage)listVerify.get(0);
					}else{
						verifyMessage.setGuid(new GUID().toString(32));
					}					
					
					verifyMessage.setCreateTime(new Date());
					verifyMessage.setReadTime(new Date());
					verifyMessage.setHidden(false);					
					verifyMessage.setReaded(false);
					//User user = (User)userManager.getObject(User.class, this.getSessionUser().getGuid());
					verifyMessage.setOperatorName(this.getSessionUser().getRealName());//后台任务应设置为：systemTask					
					verifyMessage.setReportInstanceGuid(reportInstanceGuid);
					verifyMessage.setType(Integer.valueOf(reportVerifyType));
					
					ReportInstance ri = (ReportInstance)reportInstanceManager.getObject(ReportInstance.class, reportInstanceGuid);
					verifyMessage.setTitle(ri.getReportPeriod().getName()+"-"+ri.getTemplate().getName()+"-"+ri.getApplication().getChineseName()+"-"+ri.getSoInstanceName());
					verifyMessage.setContent("请尽快填写报表.");
					reportVerifyMessageManager.saveObject(verifyMessage);					
				}
			}

			ldb.set("success", true);
			ldb.set("reason", "报表审核任务成功完成!");
			this.json = JSONObject.fromObject(ldb).toString();
		}catch(Exception e){
			ldb.set("success", false);
			ldb.set("reason", e.getMessage());
			this.json = JSONObject.fromObject(ldb).toString();
			e.printStackTrace();
		}

		return AJAX;
	}
	
	@Action(value="verifyMessageReaded")
	public String verifyMessageReaded() throws Exception {
		LazyDynaBean ldb = new  LazyDynaBean();
		try{
			ReportVerifyMessage reportVerifyMessage = (ReportVerifyMessage)reportVerifyMessageManager.getObject(ReportVerifyMessage.class, node);	
			if(reportVerifyMessage != null){
				reportVerifyMessage.setReaded(true);
				reportVerifyMessage.setReadTime(new Date());
				reportVerifyMessageManager.saveObject(reportVerifyMessage);
				ldb.set("success", true);
				ldb.set("reason", "设置已读标志，成功完成。");
			}else{
				ldb.set("success", false);
				ldb.set("reason", "没有找到这个消息。");
			}
			
			this.json = JSONObject.fromObject(ldb).toString();
		}catch(Exception e){
			ldb.set("success", false);
			ldb.set("reason", e.getMessage());
			this.json = JSONObject.fromObject(ldb).toString();
			e.printStackTrace();
		}

		return AJAX;
	}
	
	@Action(value="verifyMessageHidden")
	public String verifyMessageHidden() throws Exception {
		LazyDynaBean ldb = new  LazyDynaBean();
		try{
			ReportVerifyMessage reportVerifyMessage = (ReportVerifyMessage)reportVerifyMessageManager.getObject(ReportVerifyMessage.class, node);	
			if(reportVerifyMessage != null){
				reportVerifyMessage.setHidden(true);
				reportVerifyMessage.setReadTime(new Date());
				reportVerifyMessage.setReaded(true);
				reportVerifyMessageManager.saveObject(reportVerifyMessage);
				ldb.set("success", true);
				ldb.set("reason", "设置隐藏标志，成功完成。");
			}else{
				ldb.set("success", false);
				ldb.set("reason", "没有找到这个消息。");
			}
			
			this.json = JSONObject.fromObject(ldb).toString();
		}catch(Exception e){
			ldb.set("success", false);
			ldb.set("reason", e.getMessage());
			this.json = JSONObject.fromObject(ldb).toString();
			e.printStackTrace();
		}

		return AJAX;
	}
	
	@Action(value="list4SystemUser",
			results={@Result(name="success", location="/client/datapage/listReportInstanceAll.jsp")}
	)
	public String list4SystemUser() throws Exception {
		this.selectedAppGuid = this.getSessionUser().getDefaultApp().getGuid();
		
		List<Application> list = applicationManager.getAppsByServiceWithPermission(this.getDefaultService().getGuid(), this.getSessionUser());	
		List newList = new ArrayList();
		Map map = new HashMap();
		map.put("guid", "  ");
		map.put("name", "【全部】");
		newList.add(map);
		for(Application t : list){
			map = new HashMap();
			map.put("guid", t.getGuid());
			map.put("name", t.getChineseName());
			newList.add(map);
		}
		this.jsonApp = JSONUtil.getJsonString("include","guid,name",newList);
		
		return SUCCESS;
	}

	@Action(value="list4SystemUser4aqtb",
			results={@Result(name="success", location="/client/datapage/listReportInstance4aqtb.jsp")}
	)
	public String list4SystemUser4aqtb() throws Exception {
        if (this.selectedAppGuid == null || this.selectedAppGuid.trim().length() == 0) {
            List<Application> list = applicationManager.getAppsByServiceWithPermission(this.getDefaultService().getGuid(), this.getSessionUser());
            if (list.size() > 0) {
                this.selectedAppGuid = list.get(0).getGuid();
            }
        }

        user = (User) userManager.getObject(User.class, this.getSessionUser().getGuid());
        this.json4 = user.getLevelName();
        this.json5 = user.getLevelCode();
		
//		List<HashMap<String,Object>> list = dynaBeanManager.find("select new map(t.item_code as guid,t.item_name as name) from dyna_so_xtfl t");
//		this.json1 = JSONUtil.getJsonString(null,null,list);	
//		
//		List<HashMap<String,Object>> list2 = dynaBeanManager.find("select new map(t.item_code as guid,t.item_name as name) from dyna_so_zgdq t");
//		this.json2 = JSONUtil.getJsonString(null,null,list2);	
		
		return SUCCESS;
	}
	
	@Action(value="list4EnterpriseUser",
			results={@Result(name="success", location="/client/datapage/listReportInstanceAll.jsp")}
	)
	public String list4EnterpriseUser() throws Exception {
		List<Application> list = applicationManager.getAppByEnterpriseUser(this.getSessionUser());	
		List newList = new ArrayList();
		Map map = new HashMap();
		map.put("guid", "  ");
		map.put("name", "【全部】");
		newList.add(map);
		for(Application t : list){
			map = new HashMap();
			map.put("guid", t.getGuid());
			map.put("name", t.getChineseName());
			newList.add(map);
		}
		this.jsonApp = JSONUtil.getJsonString("include","guid,name",newList);
		
		return SUCCESS;
	}

	@Action(value="list4EnterpriseUser4aqtb",
			results={@Result(name="success", location="/client/datapage/listReportInstanceAll4aqtb.jsp")}
	)
	public String list4EnterpriseUser4aqtb() throws Exception {
		return SUCCESS;
	}
	
	@Action(value="list4EnterpriseUserWithParam",
			results={@Result(name="success", location="/client/datapage/listReportInstanceWithParam.jsp")}
	)
	public String list4EnterpriseUserWithParam() throws Exception {
		return SUCCESS;
	}
	
	@Action(value="list4EnterpriseUserWithVerifyType",
			results={@Result(name="success", location="/client/datapage/listReportInstanceWithVerifyType.jsp")}
	)
	public String list4EnterpriseUserWithVerifyType() throws Exception {
		return SUCCESS;
	}
	
	@Action(value="prepareVerifyMessageView",
			results={@Result(name="success", location="/client/datapage/verifyMessageView.jsp")}
	)
	public String prepareVerifyMessageView() throws Exception {
		reportVerifyMessage = (ReportVerifyMessage)reportVerifyMessageManager.getObject(ReportVerifyMessage.class, node);	
		if(reportVerifyMessage==null){
			reportVerifyMessage = new ReportVerifyMessage();
		}
		
		return SUCCESS;
	}
	
	@Action(value="prepareVerifyMessageWrite",
            results={@Result(name="success", location="/client/datapage/verifyMessageWrite.jsp")}
    )
    public String prepareVerifyMessageWrite() throws Exception {
        
        return SUCCESS;
    }
	
	@Action(value="listTask",
			results={@Result(name="success", location="/client/datapage/listTask.jsp")}
	)
	public String listTask() throws Exception {
		User user = getSessionUser();
		List<Application> list = applicationManager.getAppByEnterpriseUser(user);
		this.jsonApp = JSONUtil.getJsonString("include","guid,name,chineseName,tabIndex",list);
		
		return SUCCESS;
	}
	
	@Action(value="listSoInstance4EnterpriseUser",
			results={@Result(name="success", location="/client/datapage/listSoInstance4EnterpriseUser.jsp")}
	)
	public String listSoInstance4EnterpriseUser() throws Exception {
		//sos = this.getUserSOManager().getOffspringSo(selectedTask, user);
		
		List<Application> list = applicationManager.getAppByEnterpriseUser(this.getSessionUser());	
		List newList = new ArrayList();
		Map map = new HashMap();
		for(Application t : list){
			map = new HashMap();
			map.put("guid", t.getGuid());
			map.put("name", t.getChineseName());
			newList.add(map);
		}
		this.jsonApp = JSONUtil.getJsonString("include","guid,name",newList);
		
		return SUCCESS;
	}

	@Action(value="listSoInstance4SystemUser",
			results={@Result(name="success", location="/client/datapage/listSoInstance4SystemUser.jsp")}
	)
	public String listSoInstance4SystemUser() throws Exception {
		this.selectedAppGuid = this.getSessionUser().getDefaultApp().getGuid();		
		List<Application> list = applicationManager.getAppsByServiceWithPermission(this.getDefaultService().getGuid(), this.getSessionUser());
		List newList = new ArrayList();
		Map map = new HashMap();
		for(Application t : list){
			map = new HashMap();
			map.put("guid", t.getGuid());
			map.put("name", t.getChineseName());
			newList.add(map);
		}
		this.jsonApp = JSONUtil.getJsonString("include","guid,name",newList);
		
		return SUCCESS;
	}

	@Action(value="listSoInstance4SystemUser4aqtb",
			results={@Result(name="success", location="/client/datapage/listSoInstance4SystemUser4aqtb.jsp")}
	)
	public String listSoInstance4SystemUser4aqtb() throws Exception {
		return SUCCESS;
	}
	
	public ReportWindowPeriodManager getReportWindowPeriodManager() {
		return reportWindowPeriodManager;
	}

	public void setReportWindowPeriodManager(
			ReportWindowPeriodManager reportWindowPeriodManager) {
		this.reportWindowPeriodManager = reportWindowPeriodManager;
	}

	public UserManager getUserManager() {
		return userManager;
	}

	public void setUserManager(UserManager userManager) {
		this.userManager = userManager;
	}

	public UserSOManager getUserSOManager() {
		return userSOManager;
	}

	public void setUserSOManager(UserSOManager userSOManager) {
		this.userSOManager = userSOManager;
	}

	public ReportInstanceManager getReportInstanceManager() {
		return reportInstanceManager;
	}

	public void setReportInstanceManager(ReportInstanceManager reportInstanceManager) {
		this.reportInstanceManager = reportInstanceManager;
	}

	public TemplateManager getTemplateManager() {
		return templateManager;
	}

	public void setTemplateManager(TemplateManager templateManager) {
		this.templateManager = templateManager;
	}

	public EmployeeSoCollectionManager getEmployeeSoCollectionManager() {
		return employeeSoCollectionManager;
	}

	public void setEmployeeSoCollectionManager(
			EmployeeSoCollectionManager employeeSoCollectionManager) {
		this.employeeSoCollectionManager = employeeSoCollectionManager;
	}

	public SoCollectionManager getSoCollectionManager() {
		return soCollectionManager;
	}

	public void setSoCollectionManager(SoCollectionManager soCollectionManager) {
		this.soCollectionManager = soCollectionManager;
	}

	public ApplicationManager getApplicationManager() {
		return applicationManager;
	}

	public void setApplicationManager(ApplicationManager applicationManager) {
		this.applicationManager = applicationManager;
	}

	public CatalogManager getCatalogManager() {
		return catalogManager;
	}

	public void setCatalogManager(CatalogManager catalogManager) {
		this.catalogManager = catalogManager;
	}

	public StatisticalObjectTreeManager getStatisticalObjectTreeManager() {
		return statisticalObjectTreeManager;
	}

	public void setStatisticalObjectTreeManager(
			StatisticalObjectTreeManager statisticalObjectTreeManager) {
		this.statisticalObjectTreeManager = statisticalObjectTreeManager;
	}

	public DbMetaDataManager getDbMetaDataManager() {
		return dbMetaDataManager;
	}

	public void setDbMetaDataManager(DbMetaDataManager dbMetaDataManager) {
		this.dbMetaDataManager = dbMetaDataManager;
	}

	public DynaBeanManager getDynaBeanManager() {
		return dynaBeanManager;
	}

	public void setDynaBeanManager(DynaBeanManager dynaBeanManager) {
		this.dynaBeanManager = dynaBeanManager;
	}

	public ReportVerifyMessageManager getReportVerifyMessageManager() {
		return reportVerifyMessageManager;
	}

	public void setReportVerifyMessageManager(
			ReportVerifyMessageManager reportVerifyMessageManager) {
		this.reportVerifyMessageManager = reportVerifyMessageManager;
	}

	public String getJsonApp() {
		return jsonApp;
	}

	public void setJsonApp(String jsonApp) {
		this.jsonApp = jsonApp;
	}

	public String getJsonUgency() {
		return jsonUgency;
	}

	public void setJsonUgency(String jsonUgency) {
		this.jsonUgency = jsonUgency;
	}

	public String getJsonNotice() {
		return jsonNotice;
	}

	public void setJsonNotice(String jsonNotice) {
		this.jsonNotice = jsonNotice;
	}

	public String getJsonFilter() {
		return jsonFilter;
	}

	public void setJsonFilter(String jsonFilter) {
		this.jsonFilter = jsonFilter;
	}

	public String getSoInstanceCode() {
		return soInstanceCode;
	}

	public void setSoInstanceCode(String soInstanceCode) {
		this.soInstanceCode = soInstanceCode;
	}

	public String getSoInstanceName() {
		return soInstanceName;
	}

	public void setSoInstanceName(String soInstanceName) {
		this.soInstanceName = soInstanceName;
	}

	public String getSelectedAppGuid() {
		return selectedAppGuid;
	}

	public void setSelectedAppGuid(String selectedAppGuid) {
		this.selectedAppGuid = selectedAppGuid;
	}

	public String getSelectedTemplateGuid() {
		return selectedTemplateGuid;
	}

	public void setSelectedTemplateGuid(String selectedTemplateGuid) {
		this.selectedTemplateGuid = selectedTemplateGuid;
	}

	public String getSelectedPeriodTypeGuid() {
		return selectedPeriodTypeGuid;
	}

	public void setSelectedPeriodTypeGuid(String selectedPeriodTypeGuid) {
		this.selectedPeriodTypeGuid = selectedPeriodTypeGuid;
	}

	public String getSelectedSoGuid() {
		return selectedSoGuid;
	}

	public void setSelectedSoGuid(String selectedSoGuid) {
		this.selectedSoGuid = selectedSoGuid;
	}

	public String getSelectedSoTreeGuid() {
		return selectedSoTreeGuid;
	}

	public void setSelectedSoTreeGuid(String selectedSoTreeGuid) {
		this.selectedSoTreeGuid = selectedSoTreeGuid;
	}

	public String getSelectedStartSotNodeGuid() {
		return selectedStartSotNodeGuid;
	}

	public void setSelectedStartSotNodeGuid(String selectedStartSotNodeGuid) {
		this.selectedStartSotNodeGuid = selectedStartSotNodeGuid;
	}

	public String getSelectedStartSotNodeInstanceGuid() {
		return selectedStartSotNodeInstanceGuid;
	}

	public void setSelectedStartSotNodeInstanceGuid(
			String selectedStartSotNodeInstanceGuid) {
		this.selectedStartSotNodeInstanceGuid = selectedStartSotNodeInstanceGuid;
	}

	public String getSelectedEndSotNodeGuid() {
		return selectedEndSotNodeGuid;
	}

	public void setSelectedEndSotNodeGuid(String selectedEndSotNodeGuid) {
		this.selectedEndSotNodeGuid = selectedEndSotNodeGuid;
	}

	public String getSelectedSoCollectionGuid() {
		return selectedSoCollectionGuid;
	}

	public void setSelectedSoCollectionGuid(String selectedSoCollectionGuid) {
		this.selectedSoCollectionGuid = selectedSoCollectionGuid;
	}

	public String getSelectedReportInstanceGuids() {
		return selectedReportInstanceGuids;
	}

	public void setSelectedReportInstanceGuids(String selectedReportInstanceGuids) {
		this.selectedReportInstanceGuids = selectedReportInstanceGuids;
	}

	public boolean isInWindow() {
		return inWindow;
	}

	public void setInWindow(boolean inWindow) {
		this.inWindow = inWindow;
	}

	public Integer getLockStatus() {
		return lockStatus;
	}

	public void setLockStatus(Integer lockStatus) {
		this.lockStatus = lockStatus;
	}

	public Integer getReportStatus() {
		return reportStatus;
	}

	public void setReportStatus(Integer reportStatus) {
		this.reportStatus = reportStatus;
	}

	public String getReportVerifyType() {
		return reportVerifyType;
	}

	public void setReportVerifyType(String reportVerifyType) {
		this.reportVerifyType = reportVerifyType;
	}

	public ReportVerifyMessage getReportVerifyMessage() {
		return reportVerifyMessage;
	}

	public void setReportVerifyMessage(ReportVerifyMessage reportVerifyMessage) {
		this.reportVerifyMessage = reportVerifyMessage;
	}

	public ServiceManager getServiceManager() {
		return serviceManager;
	}

	public void setServiceManager(ServiceManager serviceManager) {
		this.serviceManager = serviceManager;
	}

	public String getJson1() {
		return json1;
	}

	public void setJson1(String json1) {
		this.json1 = json1;
	}

	public String getJson2() {
		return json2;
	}

	public void setJson2(String json2) {
		this.json2 = json2;
	}

	public String getJson3() {
		return json3;
	}

	public void setJson3(String json3) {
		this.json3 = json3;
	}

	public String getJson4() {
		return json4;
	}

	public void setJson4(String json4) {
		this.json4 = json4;
	}

	public String getJson5() {
		return json5;
	}

	public void setJson5(String json5) {
		this.json5 = json5;
	}

	public DataOperationManager getDataOperationManager() {
		return dataOperationManager;
	}

	public void setDataOperationManager(DataOperationManager dataOperationManager) {
		this.dataOperationManager = dataOperationManager;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public String getLevelCode() {
		return levelCode;
	}

	public void setLevelCode(String levelCode) {
		this.levelCode = levelCode;
	}

	public ReportInstanceOperationManager getReportInstanceOperationManager() {
		return reportInstanceOperationManager;
	}

	public void setReportInstanceOperationManager(
			ReportInstanceOperationManager reportInstanceOperationManager) {
		this.reportInstanceOperationManager = reportInstanceOperationManager;
	}

	public Boolean getIsForced() {
		return isForced;
	}

	public void setIsForced(Boolean isForced) {
		this.isForced = isForced;
	}

	public ReportInstanceLevelStatusManager getReportInstanceLevelStatusManager() {
		return reportInstanceLevelStatusManager;
	}

	public void setReportInstanceLevelStatusManager(
			ReportInstanceLevelStatusManager reportInstanceLevelStatusManager) {
		this.reportInstanceLevelStatusManager = reportInstanceLevelStatusManager;
	}

	public PrivilegeManager getPrivilegeManager() {
		return privilegeManager;
	}

	public void setPrivilegeManager(PrivilegeManager privilegeManager) {
		this.privilegeManager = privilegeManager;
	}

	public Integer getLevelCodeSubmitted() {
		return levelCodeSubmitted;
	}

	public void setLevelCodeSubmitted(Integer levelCodeSubmitted) {
		this.levelCodeSubmitted = levelCodeSubmitted;
	}

    public Integer getVerifyStatus() {
        return verifyStatus;
    }

    public void setVerifyStatus(Integer verifyStatus) {
        this.verifyStatus = verifyStatus;
    }
	
}
